package tt.dz.appserver.service.avro.test;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.List;

import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Parser;
import org.apache.avro.specific.AvroGenerated;
import org.apache.avro.specific.SpecificRecord;
import org.apache.avro.specific.SpecificRecordBase;

import tt.dz.appserver.util.resource.ResourceUtils;

@SuppressWarnings("unchecked")
@AvroGenerated
public class Message extends SpecificRecordBase implements SpecificRecord,Serializable {

	private static final long serialVersionUID = 1L;

	public static final Schema SCHEMA = new Parser().parse(ResourceUtils
			.getRootResource("avro/main/type/Message.json"));

	public CharSequence name;
	public int type;
	public double price;
	public boolean valid;
	public ByteBuffer content;
	public List<CharSequence> tags;

	@Override
	public Schema getSchema() {
		return SCHEMA;
	}

	@Override
	public Object get(int fieldIndex) {
		switch (fieldIndex) {
		case 0:
			return name;
		case 1:
			return type;
		case 2:
			return price;
		case 3:
			return valid;
		case 4:
			return content;
		case 5:
			return tags;
		default:
			throw new AvroRuntimeException("Bad index");
		}
	}

	@Override
	public void put(int fieldIndex, Object value) {
		switch (fieldIndex) {
		case 0:
			name = (CharSequence) value;
			break;
		case 1:
			type = (Integer) value;
			break;
		case 2:
			price = (Double) value;
			break;
		case 3:
			valid = (Boolean) value;
			break;
		case 4:
			content = (ByteBuffer) value;
			break;
		case 5:
			tags = (List<CharSequence>) value;
			break;
		default:
			throw new AvroRuntimeException("Bad index");
		}
	}

	public CharSequence getName() {
		return name;
	}

	public void setName(CharSequence value) {
		this.name = value;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer value) {
		this.type = value;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double value) {
		this.price = value;
	}

	public Boolean getValid() {
		return valid;
	}

	public void setValid(Boolean value) {
		this.valid = value;
	}

	public ByteBuffer getContent() {
		return content;
	}

	public void setContent(ByteBuffer value) {
		this.content = value;
	}

	public List<CharSequence> getTags() {
		return tags;
	}

	public void setTags(List<CharSequence> value) {
		this.tags = value;
	}
	public static void main(String[] args) {
		System.out.println(ResourceUtils
			.getRootResource("avro/main/type/transObj.json"));
	}
}
